package cmd.commands;

import java.util.logging.Level;

import model.Player;
import model.Preference;
import util.EmailSending;
import util.LoggingUtils;
import util.PlayerUtilities;

public class MemorySizeCommand extends Command {
	public MemorySizeCommand(Command c) {
		super(c.command, c.parameters);
	}

	@Override
	public boolean execute() {

		if(this.parameters==null || this.parameters.length==0) {
			return false;
		} else {
			try
			{
				Preference.getInstance().setMemorySize(Integer.parseInt(this.parameters[0]));
				Preference.getInstance().save();
				Player.getInstance().save();
				
				PlayerUtilities.setUpdateStringJson("MEMORY_SIZE",this.parameters[0]);
				LoggingUtils.log(Level.SEVERE, " Changing the memory size by "+this.parameters[0]);
			}
			catch(Exception e)
			{
				LoggingUtils.log(Level.SEVERE, "cmd.commands.MemorySizeCommand.execute() Unable to change memory size "+EmailSending.FormatException(e));
			}
		}
		return true;
	}
}
